package cn.wolfcode.p2p.business.controller;

import cn.wolfcode.p2p.anno.NeedLogin;
import cn.wolfcode.p2p.base.query.CreditTransferQueryObject;
import cn.wolfcode.p2p.business.service.ICreditTransferService;
import cn.wolfcode.p2p.util.JSONResultUtil;
import cn.wolfcode.p2p.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 债权转让
 */
@Controller
public class CredittransferController {
    @Autowired
    private ICreditTransferService creditTransferService;

    /**
     * 债权转让页面
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("can_credittransfer")
    @NeedLogin
    public String canCredittransferList(@ModelAttribute("qo")CreditTransferQueryObject qo,Model model){
        qo.setBidUserId(UserContext.getLoginInfo().getId());
        qo.setTransferState(false);
        model.addAttribute("pageResult",creditTransferService.queryCanCredittransfer(qo));
        return "credittransfer_cantrans_list";
    }
    /**
     * 债权转让
     */
    @RequestMapping("creditTransfer")
    @NeedLogin
    @ResponseBody
    public Object credittransfer(Long[] bidId){
        creditTransferService.credittransfer(bidId);
        return JSONResultUtil.jsonResult();
    }

    /**
     * 认购
     */
    @NeedLogin
    @RequestMapping("subscribe")
    @ResponseBody
    public Object subscribe(Long id){
        creditTransferService.subscribe(id);
        return JSONResultUtil.jsonResult();
    }
}
